var innerapp = angular.module('routingDemoApp', ['ngRoute', 'ngCookies'])
    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider
            .when('/', { redirectTo: '/server_watcher' })
            .when('/server_watcher', {
                templateUrl: 'views/server_watcher.html',
                controller: 'server_watcher_Ctrl'
            })
            .when('/gateway_watcher', {
                templateUrl: 'views/gateway_watcher.html',
                controller: 'gateway_watcher_Ctrl'
            })
            .when('/server_config', {
                templateUrl: 'views/server_config.html',
                controller: 'server_config_Ctrl'
            })
            .when('/geteway_config', {
                templateUrl: 'views/gateway_config.html',
                controller: 'geteway_config_Ctrl'
            })
            .when('/server_log', {
                templateUrl: 'views/server_log.html',
                controller: 'server_log_Ctrl'
            })
            .when('/software_version', {
                templateUrl: 'views/software_version.html',
                controller: 'software_version_Ctrl'
            })
            .when('/login', {
                templateUrl: 'views/login.html',
                controller: 'login_Ctrl'
            })
            .when('/user_manager', {
                templateUrl: 'views/user_manager.html',
                controller: 'user_manager_Ctrl'
            })
            .when('/db_clean', {
                templateUrl: 'views/db_clean.html',
                controller: 'db_clean_Ctrl'
            })
            .otherwise({ redirectTo: '/server_watcher' });
        // .when('/', { templateUrl: 'views/main.html' })
    }])
    .run(['$rootScope', '$location', '$cookies', function ($rootScope, $location, $cookies) {
        $rootScope.menuTitle = "";
        /* 监听路由的状态变化 */
        $rootScope.$on('$routeChangeStart', function (event, toState, toParams, fromState, fromParams) {
            if (toState.name == 'login') return;// 如果是进入登录界面则允许
            // 如果用户不存在
            if ($rootScope.user == undefined || $rootScope.user.trim() == "") {
                //$rootScope.user = $cookies.get("userName")
                /*var params = document.cookie.split(',');
                if(params.length > 0){
                    var params2 = params[0].split(':')
                    if(params2.length > 1){
                        if(params2[0] == "username"){
                            $rootScope.user = params2[1];
                            return;
                        }
                    }
                }*/
                $rootScope.location = $location
                $location.path('/login');
            } else{
                //$rootScope.user = $cookies.get("userName");
                //document.cookie = "username:" + $rootScope.user;
            }
        });
        $rootScope.$on('$routeChangeSuccess', function (evt, current, previous) {
            $rootScope.menuTitle = $location.path().substr(1)
            console.log('route have already changed ：' + $location.path());
        });
    }]);
function loadScript(url, callback) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    if (typeof (callback) != "undefined") {
        if (script.readyState) {
            script.onreadystatechange = function () {
                if (script.readyState == "loaded" || script.readyState == "complete") {
                    script.onreadystatechange = null;
                    callback();
                }
            };
        } else {
            script.onload = function () {
                callback();
            };
        }
    };
    script.src = url;
    document.body.appendChild(script);
}

function gfhdjkagf(sdsfds) {
    return md5(sdsfds)
}